package com.hainatong.jcmvvmbase.mainhome.fragment.massage;

import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.blankj.utilcode.util.DeviceUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.hainatong.jcmvvmbase.Constants;
import com.hainatong.jcmvvmbase.MvvmLazyFragment;
import com.hainatong.jcmvvmbase.R;
import com.hainatong.jcmvvmbase.databinding.FragmentRecyclerviewBinding;
import com.hainatong.jcmvvmbase.mainhome.ComFragmentActivity;
import com.hainatong.jcmvvmbase.mainhome.adapter.WarnMsgAdapter;
import com.hainatong.jcmvvmbase.mainhome.entity.WarnMsgBean;
import com.hainatong.jcmvvmbase.widget.recycleviewdriver.ListItemDecoration;
import com.hainatong.mvvmbase.base.NoViewModel;

import android.view.View;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.util.DesignUtil;

import java.util.ArrayList;
import java.util.List;

public class WarnMsgFragment extends MvvmLazyFragment<FragmentRecyclerviewBinding, NoViewModel>
{
    private WarnMsgAdapter adapter;
    @Override
    public int getLayoutId()
    {
        return R.layout.fragment_recyclerview;
    }

    @Override
    public int getBindingVariable()
    {
        return 0;
    }

    @Override
    protected void onRetryBtnClick()
    {
    }

    @Override
    protected void initView(View view)
    {
        adapter = new WarnMsgAdapter();
        viewDataBinding.refreshlayout.setRefreshHeader(new ClassicsHeader(getActivity()));
        viewDataBinding.refreshlayout.setRefreshFooter(new ClassicsFooter(getActivity()));
        viewDataBinding.recyclerview.setLayoutManager( new LinearLayoutManager(getContext()));
        viewDataBinding.recyclerview.setHasFixedSize(true);
        viewDataBinding.recyclerview.addItemDecoration( new ListItemDecoration(SizeUtils.dp2px(10)));
        viewDataBinding.recyclerview.setAdapter( adapter );
        adapter.setOnItemClickListener((adapter1, view1, position) -> {

            Bundle bundle = new Bundle();
            bundle.putString( Constants.FRAGMNET_TYPE, Constants.VIEW_WARN_MSG_DEATIL);
            ComFragmentActivity.start( getActivity(),bundle );
        });
        viewDataBinding.refreshlayout.setOnRefreshListener( refreshLayout -> {
            refreshLayout.finishRefresh(true);
        } );
        viewDataBinding.refreshlayout.setOnLoadMoreListener( refreshLayout -> {
            refreshLayout.finishLoadMore(true);
        } );


    }

    @Override
    protected void lazyLoad()
    {
        List<WarnMsgBean> msgList = new ArrayList<>();
        WarnMsgBean msg = new WarnMsgBean();
        msg.setTitle("预警信息");
        msg.setTime("2020-01-01 12:30");
        msg.setContent("火星一号船舶，设备备件-千斤顶已经不足3件，请尽快补充");
        msgList.add(msg);
        msgList.add(msg);
        msgList.add(msg);
        msgList.add(msg);
        msgList.add(msg);
        msgList.add(msg);
        msgList.add(msg);
        adapter.setList(msgList);
        adapter.notifyDataSetChanged();
    }
}
